package com.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mapper.CityMapper;
import com.mapper.CountyMapper;
import com.mapper.StreetMapper;
import com.model.City;
import com.model.County;
import com.model.Qh;
import com.model.Street;
import com.service.QhService;
@Service
public class QhServiceImpl implements QhService{

	@Autowired
	private CityMapper cityMapper;
	
	@Autowired
	private CountyMapper countyMapper;
	
	@Autowired
	private StreetMapper streetMapper;

	@Override
	public Map<String, Object> getAll() {
		
		List<City> cityList = cityMapper.getAllCitys();//市的数据
		Map<String, Object> cityMap = new HashMap<String,Object>();
		for(City city:cityList){
			Integer cityId = city.getCityId();//获取cityid作为county的pid
			String cityName = city.getCityName();
			List<County> countyList = countyMapper.getAllCountys(cityId);//查询出县区的数据 
			Map<String,Object> countyMap = new HashMap<String, Object>();//县区map
			Qh cityQh = new Qh();//市 
			for(County county:countyList){
				Integer countyId = county.getCountyId();//获取countyId作为Street的pid
				String countyName = county.getCountyName();
				Qh countyQh = new Qh();//县区 
				List<Street> streetList = streetMapper.getAllStreets(countyId);//查询出街道的数据
				Map<String,Object> streetMap = new HashMap<String, Object>();//街道map
				for(Street street:streetList){//遍历街道数据，放入map中
					String streetName = street.getStreetName();
					Integer streetId = street.getStreetId();
					streetMap.put(streetName, streetId);
				}
				countyQh.setVal(countyId);
				countyQh.setItems(streetMap);
				countyMap.put(countyName, countyQh);
			}
			cityQh.setVal(cityId);
			cityQh.setItems(countyMap);
			cityMap.put(cityName, cityQh);
		}
		return cityMap;
	}
	

}
